<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 * @version		$Id:$
 */

$this->headTitle($this->TRANSLATOR->translator('banner_list_page_title') . ' - ' .
				 $this->TRANSLATOR->translator('about_ad_title') . ' - ' .  
				 $this->TRANSLATOR->translator('common_admin_title', 'core'));
?>
<div class="content">
	<div class="box header mb0">
		<div class="head"><div></div></div>
		<h2 class="g_a_breadcump">
			<a class="fl" href="<?php echo $this->url('core_dashboard_index'); ?>"><?php echo $this->TRANSLATOR->translator('dashboard_breadcump', 'core'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="<?php echo $this->url('ad_banner_list'); ?>"><?php echo $this->TRANSLATOR->translator('banner_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('banner_list_breadcump'); ?></a>
			<div class="clear"></div>
		</h2>
	</div>
</div>
<div class="content">
	<div class="desc">
		<div class="body">
			<div class="fl">
				<h4 class="g_a_h4"><?php echo $this->TRANSLATOR->translator('banner_list_guide'); ?></h4>
				<h4 class="g_a_h4"><?php echo $this->TRANSLATOR->translator('banner_list_search_link'); ?></h4>
			</div>
			<div class="fr">
				<a class="fl g_a_tip g_a_cancel_button mr5" href="javascript: history.go(-1);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_back_button', 'core')); ?>"></a>
				<?php if ($this->ACL->isAllowed('list', 'banner')) : ?>
				<a class="fl g_a_tip" href="<?php echo $this->url('ad_banner_list'); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_list_title')); ?>">
					<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_list_icon.png" style="padding: 0 5px 0 0;" />
				</a>
				<?php endif; ?>
				<?php if ($this->ACL->isAllowed('add', 'banner')) : ?>
				<a class="fl g_a_tip" href="<?php echo $this->url('ad_banner_add'); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_add_title')); ?>">
					<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_add_icon.png" style="padding: 0 5px 0 0;" />
				</a>
				<?php endif; ?>
			</div>
			<div class="g_a_line"></div>
			<!--  -->
			<table class="g_a_data_table">
				<tbody>
					<tr>
						<th class="checkbox w_1"><input type="checkbox" name="checkbox"></th>
						<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_name_description')); ?>" class="g_a_tip_top"><?php echo $this->TRANSLATOR->translator('banner_name'); ?></th>
						<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_status')); ?>" class="g_a_tip_top"><?php echo $this->TRANSLATOR->translator('banner_status'); ?></th>
						<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_id')); ?>" class="g_a_tip_top"><?php echo $this->TRANSLATOR->translator('banner_id'); ?></th>
					</tr>
					<?php if (isset($this->banners) && $this->banners) : ?>
					<?php foreach ($this->banners as $index => $banner) : ?>
					<tr class="g_a_row" id="gAdBannerRow_<?php echo $banner['banner_id']; ?>">
						<td class="checkbox w_1"><input type="checkbox" name="checkbox"></td>
						<td>
							<div class="content"><strong><?php echo $banner['name']; ?></strong></div>
							<div class="g_a_actions buttons_demo">
								<?php if ($this->ACL->isAllowed('edit', 'banner')) : ?>
								<a class="button yellow" href="<?php echo $this->url('ad_banner_edit', $banner); ?>"><small class="icon pencil"></small><span><?php echo $this->TRANSLATOR->translator('banner_edit_action'); ?></span></a>
								<?php endif; ?>
								<?php if ($this->ACL->isAllowed('delete', 'banner')) : ?>
								<a class="button red g_a_actions_ojbect" rel="delete_<?php echo $banner['banner_id']; ?>" href="javascript: void(0);"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('banner_delete_action'); ?></span></a>
								<?php endif; ?>
								<?php if ($this->ACL->isAllowed('activate', 'banner')) : ?>
									<?php if ($banner['status'] == 'active') : ?>
									<a class="button green g_a_actions_ojbect" rel="deactivate_<?php echo $banner['banner_id']; ?>" href="javascript: void(0);"><small class="icon lock"></small><span><?php echo $this->TRANSLATOR->translator('banner_deactivate_action'); ?></span></a>
									<?php else : ?>
									<a class="button green g_a_actions_ojbect" rel="activate_<?php echo $banner['banner_id']; ?>" href="javascript: void(0);"><small class="icon unlock"></small><span><?php echo $this->TRANSLATOR->translator('banner_activate_action'); ?></span></a>
									<?php endif; ?>
								<?php endif; ?>
								<div class="clear"></div>
							</div>
						</td>
						<td class="w_8" id="gAdBannerStatus_<?php echo $banner['banner_id']; ?>">
							<?php if ($banner['status'] == 'active') : ?>
								<?php echo $this->TRANSLATOR->translator('banner_status_active'); ?>	
							<?php else : ?>
								<?php echo $this->TRANSLATOR->translator('banner_status_inactive'); ?>
							<?php endif; ?>
						</td>
						<td class="w_5"><?php echo $banner['banner_id']; ?></td>
					</tr>
					<?php endforeach; ?>
					<?php else : ?>
					<tr>
						<td colspan="5"><?php echo $this->TRANSLATOR->translator('banner_list_data_notfound'); ?></td>
					</tr>
					<?php endif; ?>
				</tbody>
			</table>
			<!--  -->
			<?php if (isset($this->pager)) : ?>	
			<!-- Pager -->
			<div class="module pagination g_a_pager">
				<?php echo $this->pager->links; ?>
			</div>
			<!-- / Pager -->
			<?php endif; ?>	
		</div>
	</div>
	<div class="body_footer">
		<div class="bottom_left"><div class="bottom_right"></div></div>
	</div>
</div>

<!--  -->
<div id="gAdBannerSearchForm" style="display: none;">
	<form action="<?php echo $this->url('ad_banner_list'); ?>" method="post">
		<h4 class="g_a_h4"><?php echo $this->TRANSLATOR->translator('banner_list_search_guide'); ?></h4>
		<p class="fl">
			<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_list_keyword'); ?></label>
			<input type="text" class="text" name="condition[keyword]" value="<?php if (isset($this->condition['keyword'])) : ?><?php echo $this->condition['keyword']; ?><?php endif; ?>" style="width: 200px;" />																						
			<br>
		</p>
		<p class="fl" style="margin-left: 5px;">
			<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_list_id'); ?></label>
			<input type="text" class="text" name="condition[banner_id]" value="<?php if (isset($this->condition['banner_id'])) : ?><?php echo $this->condition['banner_id']; ?><?php endif; ?>" style="width: 150px;" />																						
			<br>
		</p>
		<p class="fl" style="margin-left: 5px;">
			<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_status'); ?></label>
			<select class="g_a_tip_right" id="status" name="condition[status]" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_status_description')); ?>">
				<option value="">---</option>
				<option value="active"<?php if (isset($this->condition['status']) && $this->condition['status'] == 'active') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_status_active'); ?></option>
				<option value="inactive"<?php if (isset($this->condition['status']) && $this->condition['status'] == 'inactive') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_status_inactive'); ?></option>
			</select>
			<br>
		</p>
		<p class="buttons_demo fl" style="margin-left: 5px;">
			<label for="simple_input">&nbsp;</label>
			<a class="button form_submit green" href="<?php echo $this->url('ad_banner_list'); ?>"><small class="icon check"></small><span><?php echo $this->TRANSLATOR->translator('common_search_button', 'core'); ?></span></a>
			<a class="button red" href="javascript: void(0);" onclick="javascript: $(this).parents('.notice').slideUp('slow');"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('common_close_button', 'core'); ?></span></a>
		</p>
		<div class="clear"></div>
		<p class="fl">
			<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_page'); ?></label>
			<select style="width: 210px;" class="g_a_tip_right" id="route" name="condition[route]" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_page_description')); ?>">
				<option value="">---</option>
				<?php if ($this->pages) : ?>
				<?php foreach ($this->pages as $index => $page) : ?>
				<option value="<?php echo $page['route']; ?>"<?php if (isset($this->condition['route']) && $this->condition['route'] == $page['route']) : ?> selected<?php endif; ?>><?php echo $page['name']; ?></option>
				<?php endforeach; ?>
				<?php endif; ?>
			</select>
			<br>
		</p>
		<p class="fl" style="margin-left: 10px;">
			<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_zone'); ?></label>
			<select style="width: 160px;" class="g_a_tip_right" id="zone_id" name="condition[zone_id]" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_page_description')); ?>">
				<option value="">---</option>
				<?php if ($this->zones) : ?>
				<?php foreach ($this->zones as $index => $zone) : ?>
				<option value="<?php echo $zone['zone_id']; ?>"<?php if (isset($this->condition['zone_id']) && $this->condition['zone_id'] == $zone['zone_id']) : ?> selected<?php endif; ?>><?php echo $zone['code']; ?></option>
				<?php endforeach; ?>
				<?php endif; ?>
			</select>
			<br>
		</p>
	</form>
</div>
<!--  -->

<script type="text/javascript">
'Gio.Ad.Banner'.namespace();
Gio.Ad.Banner.currenAction = null;
Gio.Ad.Banner.actions = function(params) {
	/**
	 * Show g_a_ajax_loading element
	 */
	$('#g_a_ajax_loading').show();
	$.ajaxq('ad_banner_action', {
		type: 'post',
		url: params.url,
		data: params,
		success: function(response) {
			if (response == 'RESULT_OK') {
				var type = 'success';
				$('#gAdBannerRow_' + params.banner_id).addClass('g_a_row_affected');
				switch (params.act) {
					case 'delete':
						var message = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_delete_action_success')); ?>';
						$('#gAdBannerRow_' + params.banner_id).fadeOut('slow');
						break;
					case 'activate':
					case 'deactivate':
						var rel = (params.act == 'activate') ? 'deactivate_' + params.banner_id : 'activate_' + params.banner_id;
						var className = (params.act == 'activate') ? 'lock' : 'unlock';
						var text = (params.act == 'activate') ? '<?php echo $this->TRANSLATOR->translator('banner_deactivate_action'); ?>' : '<?php echo $this->TRANSLATOR->translator('banner_activate_action'); ?>';
						var textStatus = (params.act == 'activate') ? '<?php echo $this->TRANSLATOR->translator('banner_status_active'); ?>' : '<?php echo $this->TRANSLATOR->translator('banner_status_inactive'); ?>';
						var message = (params.act == 'activate') ? '<?php echo $this->TRANSLATOR->translator('banner_activate_action_success'); ?>' : '<?php echo $this->TRANSLATOR->translator('banner_deactivate_action_success'); ?>';

						$(Gio.Ad.Banner.currenAction).attr('rel', rel);
						$(Gio.Ad.Banner.currenAction).children('small:first').removeClass('lock')
														.removeClass('unlock')
														.addClass(className);
						$(Gio.Ad.Banner.currenAction).children('span:first').html(text);
						$('#gAdBannerStatus_' + params.banner_id).html(textStatus);
						break;
				}
				Gio.Message.success(message);
			} else {
				Gio.Message.error('<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_error_message', 'core')); ?>');
			}
			/**
			 * Hide g_a_ajax_loading element
			 */
			$('#g_a_ajax_loading').hide();
		}
	});
};

$(document).ready(function() {
	$('.g_a_actions .g_a_actions_ojbect').each(function() {
		var self = this;
		$(self).bind('click', function() {
			Gio.Ad.Banner.currenAction = this;
			var stringId = $(this).attr('rel');
			var temp = stringId.split('_');
			var act = temp[0];
			var id = temp[1];
			var url = ''; 
			switch (act) {
				case 'delete':
					url = '<?php echo $this->url('ad_banner_delete'); ?>';
					var messsage_confirm = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_delete_action_confirm')); ?>';
					break;
				case 'activate':
				case 'deactivate':
					url = '<?php echo $this->url('ad_banner_activate'); ?>';
					var messsage_confirm = (act == 'activate') 
												? '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_activate_action_confirm')); ?>'
												: '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_deactivate_action_confirm')); ?>';
					break;
			}
			data = { url: url, banner_id: id, act: act };
			Gio.Message.yesButton = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_yes_button', 'core')); ?>';
			Gio.Message.noButton = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_no_button', 'core')); ?>';
			Gio.Message.confirm(messsage_confirm, 'Gio.Ad.Banner.actions', data);
		});
	});

	$('.g_a_ad_banner_search_form').bind('click', function() {
		Gio.Message.form($('#gAdBannerSearchForm').html());
	});
});
</script>